﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Library
{
    public class ThirdPersonCamera: Camera
    {
        Vector3 rotation;
        Vector3 translation;
        Vector3 transform;
        Matrix modelRotation;
        Vector3 modelPosition;

        public ThirdPersonCamera(Screen Parent) : base(Parent) { }
        public ThirdPersonCamera() : base() { }

        public void RotateTranslate(Vector3 Rotation, Vector3 Translation,
            Vector3 ModelPosition, Matrix ModelRotation, Vector3 BehindTransform)
        {
            translation += Translation;
            rotation += Rotation;
            transform = BehindTransform;
            modelRotation = ModelRotation;
            modelPosition = ModelPosition;
        }

        public override void Update()
        {
            Vector3 transformedReference =
                Vector3.Transform(transform, modelRotation);
            
            Rotation = MathUtils.Vector3ToMatrix(rotation);
            translation = Vector3.Transform(translation, modelRotation);
            Position = transformedReference + modelPosition;
            translation = Vector3.Zero;
            Target = Vector3.Add(Position, Rotation.Forward);
            base.Update();
        }
    }
}
